import { create } from "zustand";
import { persist } from "zustand/middleware";
import { storage } from "./config";

import zhCN from "antd/locale/zh_CN";
import enGB from "antd/locale/en_GB";
import jaJP from "antd/locale/ja_JP";
import arEG from "antd/locale/ar_EG";
import "dayjs/locale/zh-cn";
import "dayjs/locale/en-gb";
import "dayjs/locale/ja";
import "dayjs/locale/ar";
const languagesMap = {
  zhCN,
  enGB,
  jaJP,
  arEG,
};

const useLanguageStore = create(
  persist(
    (set) => ({
      curLanguage: languagesMap.zhCN, // 使用languagesMap确保一致性
      updateLanguage: (lang) =>
        set(() => ({
          curLanguage: languagesMap[lang],
        })),
    }),
    {
      name: "language-storage",
      storage,
    }
  )
);

export default useLanguageStore;
